package l1j.server.server.serverpackets;

import l1j.server.server.model.L1Character;

public class S_HPMeter extends ServerBasePacket {
	private static final String _typeString = "[S] S_HPMeter";

	private byte[] _byte = null;

	public S_HPMeter(final int objId, final int hpRatio) {
		this.buildPacket(objId, hpRatio);
	}

	public S_HPMeter(final L1Character cha) {
		final int objId = cha.getId();
		int hpRatio = 100;
		if (0 < cha.getMaxHp()) {
			hpRatio = 100 * cha.getCurrentHp() / cha.getMaxHp();
		}

		this.buildPacket(objId, hpRatio);
	}

	private void buildPacket(final int objId, final int hpRatio) {
		this.writeC(S_OPCODE_HPMETER);
		this.writeD(objId);
		this.writeC(hpRatio);
	}

	@Override
	public byte[] getContent() {
		if (this._byte == null) {
			this._byte = this._bao.toByteArray();
		}

		return this._byte;
	}

	@Override
	public String getType() {
		return _typeString;
	}
}
